<%@ taglib prefix="c"   uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@page import = "com.db4o.servlet.Db4oServlet" %>
<%@page import = "facades.*" %>
<%@page import = "auser.*" %>
<%@page import = "com.db4o.query.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
		<script src="<%=request.getContextPath()%>/js/jquery.js"></script>
		<link rel="stylesheet"  href="<%=request.getContextPath()%>/css/print.css" type="text/css" media="print" />
		<style> 
			a{text-decoration:none}
			body{margin:0;padding:0;overflow:show}
			div.busta{width:11cm;height:22cm;border:0px solid black;page-break-after: always;writing-mode:tb-rl;padding:0;}
			div.busta div.indirizzo{
				padding:0;
				margin-right:70mm;
				margin-top:100mm;
				border:0px solid black
			}
			
			a.btnShowHide{font-size:8pt;}
			div.window{
				position:absolute;
				right:1cm;
				top:1cm;
				width:9cm;
				height:12cm;
				overflow:auto;
				border:1px solid silver;
				font-size:8pt;
				font-family:tahoma;
				overflow-x:hidden;
			}
			@media print {
				window { display:none}
			}

			div.window span{margin-left:10px;line-height:18px}
			div.window span a{font-family:"Courier New";font-size:10pt;color:navy}
			
			div.window h1{
				border-bottom:1px solid silver;margin:0;
				padding:3px;
				font-size:10pt;
				background-color:white;
			}
			div.busta div.mittente{
				font-size:10pt;	
				display:nones;
				margin-right:35mm;
				margin-top:15mm;
				border:0px solid black;
				height:6.0cm;
				width:2.5cm;
				text-align:center;
			}
			
			div.busta div.indirizzo_mit{
				padding:0;
				margin-right:10mm;
				margin-top:98mm;
				border:0px solid black
			}
			img{vertical-align:middle}
		</style>
		<script src="../js/jquery.js"></script>
	</head>
	<body>
		
	<div class='window' id='nomi' style='background-color:lightyellow'>
		<br>
		<div style='text-align:center'>
			Caricamento in corso ...&nbsp;
			<img src='<%=request.getContextPath() %>/img/loading.gif' />
		</div>
		
		
	</div>
	<script>
		var div_nomi = document.getElementById("nomi"); 
		var cumul="";
		function toggle(ID){
			
			if($("#id_" + ID).html()=="[X]"){
				$("#id_" + ID).html("[&nbsp;]");
				$("#busta_ID_" + ID).hide();
			}else{
				$("#id_" + ID).html("[X]");
				$("#busta_ID_" + ID).show();
			}
		}
		
		function launchShowAll(){
			
			$(".nominativo").html("[X]");
			restartGif();
			$(".busta").show();
			$("#img_gauge").hide();
			$("#btnHide").show();
			$("#btnShow").hide();
		}
		function showAll(){
			restartGif();
			$("#img_gauge").show();
			setTimeout("launchShowAll();",400);
		}
		
		function launchHideAll(){
			restartGif();
			$(".nominativo").html("[&nbsp;]");
			$(".busta").hide();
			$("#img_gauge").hide();
			$("#btnHide").hide();
			$("#btnShow").show();
			
		}
		
		function hideAll(){
			
			$("#img_gauge").show();
			setTimeout("launchHideAll();",400);
			
		}
		
		function restartGif(){
			//spingif.src = spingif.src;
		}
	</script>	
	<% SessionFacade sfacade = new SessionFacade(session); %> 
	<% Integer annoCorrente = new Integer(util.Conversions.getTodayYear());%>		
	<% Query qu = sfacade.newQuery(auser.Socio.class); %>
	<% Utente utente = (Utente)session.getAttribute("userBean"); %>	
	<% qu.descend("circolo").constrain(utente.getCircolo());  %> 
	<% qu.descend("annoUltimaTessera").constrain(annoCorrente).equal();  %> 
	<% qu.descend("cognome").orderAscending().descend("nome").orderAscending();  %>	
	 
	<c:if test="${param.Mittente=='Y'}">
		<c:set var="lclass" value="indirizzo_mit" />
		<c:set var="displayMit" value="block" />
	</c:if>	
	
	<c:if test="${param.Mittente!='Y'}">
		<c:set var="lclass" value="indirizzo" />
		<c:set var="displayMit" value="none" />
	</c:if>	
	<div style="font-family:tahoma;font-size:9pt; padding:3px" class="noprint">
		<a href='<%=request.getContextPath() %>/app/start/index.jsp'>Chiudi</a> 
				|<a href='javascript:print()'>Stampa</a> 
	</div>
	<c:forEach items="<%=qu.execute()%>" var="socio" varStatus="status">
		<c:set var="person" value="${socio.cognome} ${socio.nome} - ${socio.comune}" />			
		<c:set var="TitoloRef" value ="${socio.sesso=='M'?'Egr. signore':'Gent. signora'}" />
		<c:set var="ID" value ="<%=sfacade.getID("socio",pageContext) %>" />
				
				<div class='busta' id='busta_ID_${ID}' style='display:none'>
					<div class='mittente' style='display:${displayMit}'>
						<!--  img src='../images/logoa90.jpg' /-->&nbsp;
						<br>${userBean.circolo.descrizione} - ${userBean.circolo.indirizzo}
					</div>
					
					<div class='${lclass}'>
						${TitoloRef}<br>
						${socio.cognome} ${socio.nome}<br>
						${socio.via}<br>
						${socio.cap} ${socio.comune} (${socio.provincia})<br>
					</div>
				</div>
				<script>
					cumul+= '<span> <a  class=\"nominativo\" id=\"id_${ID}\" href=\'javascript:toggle(${ID})\'>[&nbsp;]</a></span><span >${person}</span><br>';
				</script>
				
			
	</c:forEach>
	
	<script>
		div_nomi.innerHTML=	"<h1 style='text-align:center'>"+
							"Nominativi</h1>" + 
							"<h1>&nbsp;"+
							"<a id='btnShow' href='javascript:showAll()' class='btnShowHide'>Seleziona Tutto | </a>" +
							"<a id='btnHide' href='javascript:hideAll()' class='btnShowHide'>Deseleziona Tutto | </a>" +
							"<span id='img_gauge' syle='font-size:8pt'>Attendere ...</span>" +
							"</h1>" +
							cumul;
							
		window.onbeforeprint = function(){
			div_nomi.style.display="none";
		}
		
		window.onafterprint = function(){
			div_nomi.style.display="block";
		}
		
		
		$("#btnHide").hide();
		$("#img_gauge").hide();
	</script>
	</body>
</html>